<template>
  <el-container>
    <el-header style="border-bottom:1px solid #fff">
      <el-row style="height:100%">
        <el-col class="logo" :span="12">
          <el-image :src="logoimg" fit="contain"></el-image>
        </el-col>
        <el-col :span="12">
          <loginshow :adminname="adminname"></loginshow>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside>
        <el-row>
          <el-col :span="24">
            <el-menu
              default-active="2"
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose"
              background-color="#000000"
              text-color="#ffffff"
              active-text-color="#ff9900"
              :router="true"
            >
              <el-submenu index="1">
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>管理员管理</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item index="/addnewadmin">添加管理员</el-menu-item>
                  <el-menu-item index="/adminlist">管理员列表</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <el-submenu index="2">
                <template slot="title">
                  <i class="el-icon-user"></i>
                  <span>用户管理</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item index="usersList">全部用户</el-menu-item>
                  <el-menu-item index="auditList">审核管理</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <el-submenu index="3">
                <template slot="title">
                  <i class="el-icon-truck"></i>
                  <span>车辆管理</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item index="/carsList">车辆列表</el-menu-item>
                </el-menu-item-group>
                <el-menu-item-group>
                  <el-menu-item index="/carSearch">车辆查找</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <el-submenu index="4">
                <template slot="title">
                  <i class="el-icon-tickets"></i>
                  <span>订单管理</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item index="/orderlist">订单列表</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <el-submenu index="5">
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>数据统计</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item index="5-1">选项1</el-menu-item>
                  <el-menu-item index="5-2">选项2</el-menu-item>
                  <el-menu-item index="5-3">选项3</el-menu-item>
                  <el-menu-item index="5-4">选项4</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import axios from "axios";
import loginshow from "../components/admin/loginshow";
export default {
  components: {
    loginshow
  },
  data() {
    return {
      logoimg: require("../assets/indexlogo.png"),
      adminname: ""
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    }
  },
  beforeRouteEnter(to, from, next) {
    axios.get("/admin/islogin").then(res => {
      if (res.data.islogin) {
        next(vm => {
          // 通过 `vm` 访问组件实例
          vm.adminname = res.data.currentadmin;
        });
      } else {
        next({ path: "/login" });
      }
    });
  }
};
</script>

<style  scoped>
#app > .el-container {
  min-height: 100vh;
}
.logo {
  height: 100%;
  text-align: left;
}
.logo .el-image {
  height: 100%;
}
.el-menu {
  border: none;
}
</style>